<template>
  <div class="page-container">
    <div class="page-content">
      <!-- 顶部 -->
      <div style="display: flex;align-items: center;margin: 0px 0 0 30px;">
        <h2 style="color:black;margin-top: 0px;margin-left: 37%;text-align: center; font-size: 30px; font-weight:900;color:#777777;">每日健康登记管理系统</h2>
      </div>
      <!-- 中部 -->
      <div style="margin-top: 30px;margin-left: 80px; display: flex;align-items: center;">
        <!-- 表单 -->
        <div style="margin-left: 18%;margin-top: -20px">
          <div style="height: 380px;width: 500px;border: solid 1px gray;margin-bottom: 50px;margin-left: 100px; border-radius: 20px;box-shadow:0px 0px 20px rgb(161, 244, 250);background-color: white;">
            <div style="text-align: center;margin-top: 50px;">
              <h3 style="text-align: center; font-size: 20px; font-weight:900;">欢迎登录每日健康登记管理系统</h3>
            </div>
            <el-form
              :model="form"
              status-icon
              :rules="rules"
              ref="loginForm"
              label-width="100px"
              class="loginForm"
              style="width: 85%;margin-top: 50px;text-align: center;"
            >
              <el-form-item label="账号">
                <el-input v-model="form.userNumber"></el-input>
              </el-form-item>
              <el-form-item label="密码">
                <el-input
                  v-model="form.userPassword"
                  show-password
                ></el-input>
              </el-form-item>
              <el-form-item style="margin-top: 50px;">
                <!-- <el-button type="primary">注册</el-button> -->
                <el-button
                  type="success"
                  @click.prevent="submitLogin()"
                  native-type="submit"
                >登录</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import axios from 'axios'
export default {
  name: 'Login',
  data () {
    return {
      name:'',
      form: {
        userNumber: '',
        userPassword: ''
      },
      rules: {}
    }
  },
  computed: {},
  created () {},
  mounted () {},
  methods: {
    open4() {
      this.$message.error('账号或密码错误');
    },
    submitLogin () {
      let postData = this.$qs.stringify({
        username:this.form.userNumber,
        password:this.form.userPassword,
      });
      axios.post(`http://localhost:8181/user/login`,postData)
        .then(res=>{
          //console.log(res.data)
          if(res.status===200){
            if(res.data==="管理员"){
              this.$router.replace({ path: "/manager" });
            }
            else if(res.data==="账号或密码错误"){
              this.open4();
            }
            else{
              this.$store.state.textData =res.data;
              this.$router.replace({ path: "/student" });
            }
          }
        })
    }
  }}
</script>

<style>
  .footer{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 1vh;
    width: 95%;
    font-size: 12px;
    color: #777;
  }
  .footer div{
    margin: 0.5vh;
  }
  .page-container {
    position: relative;
    height: 100vh;
    width: 100vw;
    flex: 1 1 0%;
  }

  .visual-bg {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    opacity: 85%;
  }

  .visual-bg > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .page-content {
    position: relative;
    z-index: 3;
  }
</style>
